import{
  myProductsFeatured,
  myCutFeatured
}from "../../../api.js"
var app = getApp().globalData
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mylist:[],
    interested_list: [],
    listNone:true,
    whether:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    myProductsFeatured(app.Store.token).then(res =>{
      console.log(res)
      if(res.data.code == 666){
        that.setData({
          listNone:false,
          mylist:res.data.data
        })
        that.cut_list()
      }
    })
  },
  cut_list(){
    var that = this
    myCutFeatured(app.Store.token).then(res => {
      if (res.data.code == 666) {
        var now_time = new Date(res.data.data.time.now.replace(/\-/g, "/")).getTime()
        var start_time = new Date(res.data.data.time.activity_start_time.replace(/\-/g, "/")).getTime()
        var end_time = new Date(res.data.data.time.activity_end_time.replace(/\-/g, "/")).getTime()
        if (now_time > start_time) {
          that.data.whether = true
        }
        that.setData({
          interested_list: res.data.data,
          whether: that.data.whether
        })
      }
    })
  },
  onHide: function () {
    getApp().endpage(new Date().getTime())
  },
  onShow:function(){
    getApp().startpage(new Date().getTime())
  },
  goactiv(e) {
    var id = e.currentTarget.dataset.id
    var index = e.currentTarget.dataset.index
    wx.navigateTo({
      url: '/pages/activity/details/details?id=' + id + '&enter_type=7&label=3&position=' + index,
    })
  },
  golist(){
    wx.navigateBack({
      delta: 1
    })
  },
  goShop(e){
    var id = e.currentTarget.dataset.bat
    wx.navigateTo({
      url: '/pages/money/submit/submit?batchcode=' + id,
    })
  },
  goBat(e){
    var id = e.currentTarget.dataset.bat
    wx.navigateTo({
      url: '/pages/money/detail/detail?batchcode=' + id,
    })
  },
  goproduct(e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/public/productdetail/productdetail?id=' + id,
    })
  },
  godingdan(e){
    var id = e.currentTarget.dataset.ind
    var fomr = this.data.mylist.my_cut[id]
    let keyArr = Object.keys(fomr)
    let map = Object.create(null)
    let k;
    for (let i = 0, l = keyArr.length; i < l; i++) {
      k = keyArr[i]
      map[k] = encodeURIComponent(fomr[k])
    }
    wx.navigateTo({
      url: '/pages/money/settlement/settlement?product=' + JSON.stringify([map]) + '&order_enter_type=4'
    })
  },
  gotolist(e){
    wx.navigateTo({
      url: '/pages/activity/list/list',
    })
  }
})